# @HEADER
# ************************************************************************
#
#            TriBITS: Tribal Build, Integrate, and Test System
#                    Copyright 2013 Sandia Corporation
#
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the Corporation nor the names of the
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ************************************************************************
# @HEADER

##############################################################################
#
# CMake variable for use by ${PROJECT_NAME}/${PACKAGE_NAME} clients.
#
# ${DISCOURAGE_EDITING}
#
##############################################################################

if(CMAKE_VERSION VERSION_LESS 3.3)
  set(${PDOLLAR}{CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
    "${PACKAGE_NAME} requires CMake 3.3 or later for 'if (... IN_LIST ...)'"
    )
  set(${PDOLLAR}{CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
  return()
endif()
cmake_minimum_required(VERSION 3.3...${TRIBITS_CMAKE_MINIMUM_REQUIRED})

## ---------------------------------------------------------------------------
## Compilers used by ${PROJECT_NAME}/${PACKAGE_NAME} build
## ---------------------------------------------------------------------------

set(${EXPORT_FILE_VAR_PREFIX}_CXX_COMPILER "${CMAKE_CXX_COMPILER_FOR_CONFIG_FILE}")

set(${EXPORT_FILE_VAR_PREFIX}_C_COMPILER "${CMAKE_C_COMPILER_FOR_CONFIG_FILE}")

set(${EXPORT_FILE_VAR_PREFIX}_Fortran_COMPILER "${CMAKE_Fortran_COMPILER_FOR_CONFIG_FILE}")
# Deprecated!
set(${EXPORT_FILE_VAR_PREFIX}_FORTRAN_COMPILER "${CMAKE_Fortran_COMPILER_FOR_CONFIG_FILE}") 


## ---------------------------------------------------------------------------
## Compiler flags used by ${PROJECT_NAME}/${PACKAGE_NAME} build
## ---------------------------------------------------------------------------

## Give the build type
set(${EXPORT_FILE_VAR_PREFIX}_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")

## Set compiler flags, including those determined by build type
set(${EXPORT_FILE_VAR_PREFIX}_CXX_FLAGS [[${CMAKE_CXX_FLAGS_ESCAPED} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}]])

set(${EXPORT_FILE_VAR_PREFIX}_C_FLAGS [[${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}]])

set(${EXPORT_FILE_VAR_PREFIX}_Fortran_FLAGS [[${CMAKE_FORTRAN_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}]])
# Deprecated
set(${EXPORT_FILE_VAR_PREFIX}_FORTRAN_FLAGS [[${CMAKE_FORTRAN_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}]])

## Extra link flags (e.g., specification of fortran libraries)
set(${EXPORT_FILE_VAR_PREFIX}_EXTRA_LD_FLAGS [[${${PROJECT_NAME}_EXTRA_LINK_FLAGS}]])

## This is the command-line entry used for setting rpaths. In a build
## with static libraries it will be empty.
set(${EXPORT_FILE_VAR_PREFIX}_SHARED_LIB_RPATH_COMMAND "${SHARED_LIB_RPATH_COMMAND}")
set(${EXPORT_FILE_VAR_PREFIX}_BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}")

set(${EXPORT_FILE_VAR_PREFIX}_LINKER ${CMAKE_LINKER})
set(${EXPORT_FILE_VAR_PREFIX}_AR ${CMAKE_AR})

## ---------------------------------------------------------------------------
## Set library specifications and paths
## ---------------------------------------------------------------------------

## Base install location (if not in the build tree)
set(${EXPORT_FILE_VAR_PREFIX}_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@")

## List of package libraries
set(${EXPORT_FILE_VAR_PREFIX}_LIBRARIES ${PACKAGE_NAME}::all_libs)

## ---------------------------------------------------------------------------
## MPI specific variables
##   These variables are provided to make it easier to get the mpi libraries
##   and includes on systems that do not use the mpi wrappers for compiling
## ---------------------------------------------------------------------------

set(${EXPORT_FILE_VAR_PREFIX}_MPI_LIBRARIES "${TPL_MPI_LIBRARIES}")
set(${EXPORT_FILE_VAR_PREFIX}_MPI_LIBRARY_DIRS "${TPL_MPI_LIBRARY_DIRS}")
set(${EXPORT_FILE_VAR_PREFIX}_MPI_INCLUDE_DIRS "${TPL_MPI_INCLUDE_DIRS}")
set(${EXPORT_FILE_VAR_PREFIX}_MPI_EXEC "${MPI_EXEC}")
set(${EXPORT_FILE_VAR_PREFIX}_MPI_EXEC_MAX_NUMPROCS "${MPI_EXEC_MAX_NUMPROCS}")
set(${EXPORT_FILE_VAR_PREFIX}_MPI_EXEC_NUMPROCS_FLAG "${MPI_EXEC_NUMPROCS_FLAG}")

## ---------------------------------------------------------------------------
## Set useful general variables
## ---------------------------------------------------------------------------

${PACKAGE_CONFIG_CODE}

## ----------------------------------------------------------------------------
## Create deprecated non-namespaced library targets for backwards compatibility
## ----------------------------------------------------------------------------

set(${EXPORT_FILE_VAR_PREFIX}_EXPORTED_PACKAGE_LIBS_NAMES "${EXPORTED_PACKAGE_LIBS_NAMES}")

foreach(libname IN LISTS ${EXPORT_FILE_VAR_PREFIX}_EXPORTED_PACKAGE_LIBS_NAMES)
  if (NOT TARGET ${PDOLLAR}{libname})
    add_library(${PDOLLAR}{libname} INTERFACE IMPORTED)
    target_link_libraries(${PDOLLAR}{libname}
       INTERFACE ${PACKAGE_NAME}::${PDOLLAR}{libname})
    set(deprecationMessage
      "WARNING: The non-namespaced target '${PDOLLAR}{libname}' is deprecated!"
      "  If always using newer versions of the project '${PROJECT_NAME}', then use the"
      " new namespaced target '${PACKAGE_NAME}::${PDOLLAR}{libname}', or better yet,"
      " '${PACKAGE_NAME}::all_libs' to be less sensitive to changes in the definition"
      " of targets in the package '${PACKAGE_NAME}'.  Or, to maintain compatibility with"
      " older or newer versions the project '${PROJECT_NAME}', instead link against the"
      " libraries specified by the variable '${PACKAGE_NAME}_LIBRARIES'."
      )
    string(REPLACE ";" "" deprecationMessage "${PDOLLAR}{deprecationMessage}")
    set_target_properties(${PDOLLAR}{libname}
      PROPERTIES DEPRECATION "${PDOLLAR}{deprecationMessage}" )
  endif()
endforeach()
